package com.yuexun.beilunpatient.ui.contractmanage.presenter.impl;

import com.yuexun.beilunpatient.base.BaseEntity;
import com.yuexun.beilunpatient.ui.contractmanage.bean.HospitalizationRecordBean;
import com.yuexun.beilunpatient.ui.contractmanage.model.IContractManageModel;
import com.yuexun.beilunpatient.ui.contractmanage.presenter.IHospitalizationRecordPresenter;
import com.yuexun.beilunpatient.ui.contractmanage.ui.view.IHospitalizationRecordView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by chenss on 2018/11/30.
 */
public class HospitalizationRecordPresenter implements IHospitalizationRecordPresenter {

    private IHospitalizationRecordView view;
    private IContractManageModel model;

    public HospitalizationRecordPresenter(IHospitalizationRecordView view, IContractManageModel model) {
        this.view = view;
        this.model = model;
    }

    @Override
    public void inquireHospitalizationHistory(Map<String, String> praise) {
        model.inquireHospitalizationHistory(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<HospitalizationRecordBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("获取患者住院就诊记录失败");
                    }

                    @Override
                    public void onNext(BaseEntity<HospitalizationRecordBean> bean) {
                        view.getHospitalizationHistory(bean);
                    }
                });
    }
}
